//
//  DWJMainViewController.swift
//  weibo
//
//  Created by 代伟佳 on 16/4/16.
//  Copyright © 2016年 代伟佳. All rights reserved.
//

import UIKit

class DWJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 初始化tabBar
        let tabbar = DWJTabBar()
        
        tabbar.DWJDelegate = self
        
        // 通过KVC设置 系统私有属性 不能直接设置
        setValue(tabbar, forKey: "tabBar")
        
        
        addChildViewController(DWJHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(DWJMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DWJDiscoveryViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(DWJProfileViewController(), imageName: "tabbar_profile", title: "我")

    }
    
    // 添加子控制器
    func addChildViewController(childController: UIViewController,  imageName: String, title: String) {
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        
        childController.title = title
        
        addChildViewController(UINavigationController(rootViewController: childController))
        
        
        
    }

}

// MARK: - DWJTabBarDelegate
// 相当于OC中的分类 当前类的分类
extension DWJMainViewController: DWJTabBarDelegate {

    func composeButtonClick() {

    }
}
